from django import template
register = template.Library()

from settings import URL_PATH

from drill.models import Lesson, Drill, Document


#from django.template.defaultfilters import stringfilter

@register.filter(name='foobar')
def foobar(context):
    #timezone = context['timezone']
    #return your_get_current_time_method(timezone, format_string)
    return 'foobarstring'

#register.simple_tag(takes_context=True)(foobar)

@register.filter(name='cut')
def cut(value, arg):
    return value.replace(arg, '')
    

TEMPL = '''
%s - %s <br/>
<div style='margin-top: 10px;'>
%s
</div>
'''
ITEM_TEMPL = '''<a href='%s/%s/%s/%s' class='lesson_a active '> %s </a>'''

@register.simple_tag
def menu(lesson):
    assert type(lesson) == Lesson, ('%s' % type(lesson))
    #warning = kwargs['warning']
    #profile = kwargs['profile']
    #s = [ITEM_TEMPL % (s) for s in ['doc1', 'doc2', 'drill1', 'drill2']
    #lesson_sname = request.path_info.split('/')[1]
    #lesson = Lesson.objects.get(sname=lesson_sname)
    documents = lesson.get_documents()
    drills = lesson.get_drills()
    #l = []
    #l.extend([ITEM_TEMPL % (URL_PATH, lesson.sname, 'document', d.sname, d.name) for d in documents])
    #l.extend([ITEM_TEMPL % (URL_PATH, lesson.sname, 'drill', d.sname, d.name) for d in drills])
    #s = '\n'.join(l)
    
    s = '''<a href='%s/%s/document/lesson_plan' class='lesson_a active '> Lesson plan </a>''' % (URL_PATH, lesson.sname) 
    s += '''<a href='%s/%s/document/tutorial' class='lesson_a active '> Tutorial </a>''' % (URL_PATH, lesson.sname) 
    s += '''<a href='%s/%s/drill_list' class='lesson_a active '> List of drills </a>''' % (URL_PATH, lesson.sname) 
    s += '''<a href='%s/%s/document/texts' class='lesson_a active '> Texts </a>''' % (URL_PATH, lesson.sname) 
    s += '''<a href='%s/%s/document/extra' class='lesson_a active '> Extra </a>''' % (URL_PATH, lesson.sname) 
    return TEMPL % (lesson.name, lesson.shortdescr, s)
